/*
 * @file    sub_str1.cpp
 * @author  edward <libo@tencent.com>
 * @date    2013-04-17
 * @brief   
 * */

#include <iostream>

template<typename T, size_t num1, size_t num2>
int sub_str( T (&pattern)[num1], T (&text)[num2]) {
    int i, j, sz1 = sizeof(pattern) / sizeof(pattern[0]);
    int sz2 = sizeof(text) / sizeof(text[0]);
    if(sz2 < sz1) return -1;
    for(i = 0, j = 0; i < sz2 && j < sz1; i++) {
        if(pattern[j] == text[i]) j++;
        else { i -= j; j = 0; }
        
    }
    if(j == sz1) {
            return i - j;
    }
    return -1;
}

int main() {
    char pattern[] = "aba";
    char text[] = "sdadaaba";
    int pattern2[] = {12,23};
    int text2[] = {12,34,12,23,234};
    //std::cout << sub_str(pattern, text);
    std::cout << sub_str(pattern2, text2);
    return 0;
}
